package com.golf.core.course.bodies;

import java.util.Collection;
import java.util.HashMap;

/**
 * NB: Nowhere near thread safe !!!!!
 * 
 * @author gareth
 */
public class CourseBodies
{
    
    private HashMap<String, CourseBody> nameBodyMap; 

    
    private HashMap<String, CourseBody> idBodyMap; 
    
    
    public CourseBodies()
    {
        nameBodyMap  = new HashMap<String, CourseBody>();
        idBodyMap  = new HashMap<String, CourseBody>();
    }
    
    
    public void add(CourseBody body)
    {
        nameBodyMap.put(body.name(), body);
        idBodyMap.put(String.valueOf(body.getId()), body);
    }
    
    
    public Collection<CourseBody> getBodies()
    {
        return nameBodyMap.values();
    }
    
    public CourseBody getBodyByName(final String name)
    {
        return nameBodyMap.get(name);
    }
    
    public CourseBody getBodyById(final int id)
    {
        return idBodyMap.get(String.valueOf(id));
    }


    public void updateNamedBodyWithId(CourseBody body, int id)
    {
        final CourseBody b = nameBodyMap.get(body.name());
        idBodyMap.put(String.valueOf(id), b);
    }
    
}
